package cz.khfotbal.beans;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cz.khfotbal.domain.Player;
import cz.khfotbal.service.PlayerService;

@Component
@Scope(value = "session")
public class PlayerBean {

	@Autowired
	private PlayerService playerService;

	private Player newPlayer;
	private Player selectedPlayer;
	private List<Player> filteredPlayers;
	private String firstname;

	public PlayerBean() {
		newPlayer = new Player();
		selectedPlayer = new Player();
	}

	public Player getNewPlayer() {
		return newPlayer;
	}

	public List<Player> getPlayerList() {
		return playerService.getAllPlayers();
	}

	public void updatePlayer() {
		if (selectedPlayer != null) {
			playerService.updatePlayer(selectedPlayer);
		}
	}

	public void createPlayer() {
		newPlayer.setFirstname(firstname);
		playerService.createPlayer(newPlayer);
		newPlayer = new Player();
		firstname = "";
	}

	public void deletePlayer() {
		playerService.deletePlayer(selectedPlayer);
	}

	public void setNewPlayer(Player newPlayer) {
		this.newPlayer = newPlayer;
	}

	public Player getSelectedPlayer() {
		return selectedPlayer;
	}

	public void setSelectedPlayer(Player selectedPlayer) {
		this.selectedPlayer = selectedPlayer;
	}

	public List<Player> getFilteredPlayers() {
		return filteredPlayers;
	}

	public void setFilteredPlayers(List<Player> filteredPlayers) {
		this.filteredPlayers = filteredPlayers;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

}
